package o;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.ui.css.CSSStyleSheet;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.CopyOnWriteArrayList;

public class cia {
    public int ʻ;
    protected Context ʼ;
    protected boolean ʽ = true;
    public CSSStyleSheet csSheet;
    protected Bundle ˋॱ = new Bundle();
    public boolean ˎ = false;
    private e ˏ = e.DEFAULT;
    protected int ͺ = 0;
    private String ॱ;
    protected List<chz> ॱॱ = new CopyOnWriteArrayList();
    protected c ᐝ = null;

    public interface c {
        void onDataUpdated();
    }

    public enum e {
        DEFAULT,
        NORMAL_PAGE,
        CSS_PAGE
    }

    public cia(Context context) {
        this.ʼ = context.getApplicationContext();
    }

    public Bundle ʽ() {
        return this.ˋॱ;
    }

    public void ॱ(c cVar) {
        this.ᐝ = cVar;
    }

    public boolean ᐝ() {
        return this.ʽ;
    }

    public void ˊ(boolean z) {
        this.ʽ = z;
        if (!z) {
            CardBean ˋ = ˋ();
            if (ˋ != null) {
                ˋ.ʻ(true);
            }
        }
    }

    public chz ˋ(long j, int i, int i2, List<CardBean> list) {
        return ॱ(j, i, i2, list, null);
    }

    public chz ॱ(long j, int i, int i2, List<CardBean> list, String str) {
        return ˎ(j, i, i2, list, str, this.ॱॱ.size());
    }

    public chz ˎ(long j, int i, int i2, List<CardBean> list, String str, int i3) {
        chz ˎ = ˎ(j, i, i2, list, str);
        if (ˎ == null) {
            ccn.ˏ.ˊ("CardDataProvider", "addCardChunk, node == null, cardType = " + i);
            return null;
        }
        this.ॱॱ.add(i3, ˎ);
        return ˎ;
    }

    public void ˎ(List<chz> list, int i) {
        if (ˏ((List) list)) {
            ccn.ˏ.ˊ("CardDataProvider", "addCardChunks, cardChunks is empty");
        } else {
            this.ॱॱ.addAll(i, list);
        }
    }

    public chz ˎ(long j, int i, int i2, List<CardBean> list, String str) {
        cie ˋ = cib.ˋ(this.ʼ, i);
        if (ˋ == null) {
            ccn.ˏ.ˊ("CardDataProvider", "addCardChunk, node == null, cardType = " + i);
            return null;
        }
        chz o_chz = new chz(j, ˋ, i2, list);
        int i3 = this.ͺ;
        this.ͺ = i3 + 1;
        o_chz.ˊ(i3);
        o_chz.ˏ(str);
        return o_chz;
    }

    public CardBean ˏ(String str) {
        if (!(ˏ(this.ॱॱ) || TextUtils.isEmpty(str))) {
            ListIterator listIterator = this.ॱॱ.listIterator(this.ॱॱ.size());
            while (listIterator.hasPrevious()) {
                CardBean ˊ = ((chz) listIterator.previous()).ˊ(str);
                if (ˊ != null) {
                    return ˊ;
                }
            }
        }
        return null;
    }

    public void ॱॱ() {
        if (this.ॱॱ != null) {
            this.ॱॱ.clear();
        }
    }

    public int ˊॱ() {
        int i = 0;
        for (chz ॱ : this.ॱॱ) {
            i = ॱ(ॱ) + i;
        }
        return i;
    }

    private CardBean ˋ() {
        if (!ˏ(this.ॱॱ)) {
            ListIterator listIterator = this.ॱॱ.listIterator(this.ॱॱ.size());
            while (listIterator.hasPrevious()) {
                CardBean ˎ = ((chz) listIterator.previous()).ˎ();
                if (ˎ != null) {
                    return ˎ;
                }
            }
        }
        return null;
    }

    public chz ॱ(long j) {
        for (chz o_chz : this.ॱॱ) {
            if (o_chz.ˏ == j) {
                return o_chz;
            }
        }
        return null;
    }

    public boolean ˏॱ() {
        return this.ॱॱ.isEmpty();
    }

    public int ॱˊ() {
        return this.ॱॱ.size();
    }

    public chz ˏ(int i) {
        int i2 = 0;
        int i3 = 0;
        for (chz o_chz : this.ॱॱ) {
            int ॱ = ॱ(o_chz);
            i3 += ॱ;
            if (i3 > i) {
                o_chz.ॱ = (i - i2) * o_chz.ˋ.ˏ();
                return o_chz;
            }
            i2 += ॱ;
        }
        return null;
    }

    public int ˎ(int i) {
        int i2 = 0;
        for (chz o_chz : this.ॱॱ) {
            i2 += ॱ(o_chz);
            if (i + 1 <= i2) {
                return o_chz.ˋ.ͺ();
            }
        }
        return -1;
    }

    public int ॱ(chz o_chz) {
        int i = o_chz.ˊ;
        if (i < 0 || o_chz.ˋ.ˏ() * i > o_chz.ˋ()) {
            return (int) ((((float) o_chz.ˋ()) / ((float) o_chz.ˋ.ˏ())) + 0.9f);
        }
        return i;
    }

    public void ͺ() {
        ˋॱ();
    }

    public void ˋॱ() {
        if (this.ᐝ != null) {
            this.ᐝ.onDataUpdated();
        }
    }

    public void ˏ(boolean z) {
        ˎ(z, true);
    }

    public void ˎ(boolean z, boolean z2) {
        if (z) {
            this.ˎ = true;
        } else if (this.ˎ && z2) {
            ॱॱ();
            this.ˎ = false;
        }
    }

    public void ˋ(boolean z) {
        if (z) {
            this.ˏ = e.DEFAULT;
        }
        if (this.ˏ == e.DEFAULT) {
            this.ˏ = this.csSheet != null ? e.CSS_PAGE : e.NORMAL_PAGE;
        }
    }

    public boolean ॱˋ() {
        return this.ˏ == e.CSS_PAGE;
    }

    public List<chz> ʻॱ() {
        return this.ॱॱ;
    }

    public void ॱ() {
    }

    private <V> boolean ˏ(List<V> list) {
        return list == null || list.isEmpty();
    }

    public String toString() {
        return " CardDataProvider {\n\tsize: " + ॱˊ() + "\n\thasMore: " + this.ʽ + "\n\targ: " + this.ˋॱ + "\n\tfromCache: " + this.ˎ + "\n}";
    }

    public String ॱᐝ() {
        return this.ॱ;
    }

    public void ˎ(String str) {
        this.ॱ = str;
    }
}
